<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/4/14
  Time: 13:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>首页</title>
    <link href="${pageContext.request.contextPath}/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/plugins/bootstrap-table/bootstrap-table.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/font-awesome.min93e3.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/style.min.css?v=4.1.0" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/font-awesome.min93e3.css" rel="stylesheet">
</head>

<body>

<div class="wrapper wrapper-content animated fadeInRight">
    <h1>欢迎登陆斑马线交规驾考后台管理系统！</h1>
    <h4 id="useronline"></h4>
    <h4 id="subjectcount"></h4>

    <div style="margin: 10px"><i class="fa fa-twitter"></i>
        <span style="font-size: large">在线用户</span><span style="font-size: large" id="onlineCount"></span>
    </div>
    <table id="onlinetable" data-mobile-responsive="true"></table>

</div>

</body>

<script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/static/layer/layer.js"></script>
<script src="${pageContext.request.contextPath}/static/js/content.min.js"></script>


<script src="${pageContext.request.contextPath}/static/js/plugins/iCheck/icheck.min.js"></script>

<%--bootstrap table--%>
<script src="${pageContext.request.contextPath}/static/js/plugins/bootstrap-table/bootstrap-table.js"></script>
<script src="${pageContext.request.contextPath}/static/js/plugins/bootstrap-table/bootstrap-table-mobile.js"></script>
<script src="${pageContext.request.contextPath}/static/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>


<script>
    $(".i-checks").iCheck({
        checkboxClass: "icheckbox_square-green",
        radioClass: "iradio_square-green"
    });


     $(function () {
         $.ajax({
             url: '/user/online',
             type: 'put',
             dataType: "json",
             success: function (result) {
                 var data = JSON.stringify(result.onlineUser);
                 $("#useronline").html("当前系统共有会员："+result.userCount+" 名");
                 $("#subjectcount").html("当前系统共有考题："+result.subjectCount+" 道");
$("#onlineCount").html(" ( 共"+result.onlineUser.length+"人在线)");
             }
         });
     });


    $("#onlinetable").bootstrapTable({
        url: '/user/online',
        method: 'put',
        striped: true,
        cache: false,
        height: 630,
        pagination: true,
        sidePagination: "client",
        pageNumber: 1,
        pageSize: 15,
        pageList: [],
        queryParams: function (params) { // 请求服务器数据时发送的参数，可以在这里添加额外的查询参数，返回false则终止请求

        },
        responseHandler: function (res) {
            return res.onlineUser;
        },
        columns: [
            {
                field: 'id',
                title: '用户ID'
            }, {
                field: 'username',
                title: '用户名'
            }, {
                field: 'ip',
                title: '最近登录ip'
            }, {
                field: 'updatetime',
                title: '最近登录时间',
                formatter: function (value) {
                    if (!value) {
                        return "-";
                    } else {
                        var crtTime = new Date(parseInt(value) * 1000);
                        return timeformat("yyyy-MM-dd hh:mm:ss", crtTime);
                    }
                }
            }
        ]
    })
    //格式化时间
    function timeformat(fmt, date) {
        var o = {
            "M+": date.getMonth() + 1,                 //月份
            "d+": date.getDate(),                    //日
            "h+": date.getHours(),                   //小时
            "m+": date.getMinutes(),                 //分
            "s+": date.getSeconds(),                 //秒
            "S": date.getMilliseconds()             //毫秒
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }

</script>

</html>
